from dataclasses import asdict

import pinia
from console_conpent.select import select
from console_conpent.table import dicts2table
from data.config.DefaultConfig import player_data
from effect.util.console.SuperConsole import cls, readKey
from effect.util.console.playerdata_print import pprint
from effect.util.console.showMySlave import ShowMySlave
from entiys.map.MapSaveManager import MapSaveManager
from entiys.methods.augument.SaveAttribute import SaveAttribute
from entiys.npc.NPCLoader import NPCLoader
from game.TopClass.withSaveInfo import WithSaveInfoWindows
from game_control.save.saveManager import SaveManager


class MapManager(WithSaveInfoWindows):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.saveattribute: SaveAttribute = kwargs.get("saveattribute")
        self.mapSaveManager: MapSaveManager = self.saveattribute.mapJSON()

        self.mode = "dy"

    def UiShow(self):
        cls()

        if self.mode == "dy":
            point = self.getAllDy()
        else:
            point = self.mapSaveManager.getPointByDy(self.mode)
            print(point, self.mode)
            readKey()
        _select = select(
            title="请选择你要前往的国家" if self.mode == "dy" else "请选择你要前往的城市",
            options=["返回"] + point,
        )
        if self.mode != "dy":
            _select.tips = [lambda:"返回"] + dicts2table([self.mapSaveManager.getPointDetail(i) for i in point])
            _select.print_mode = "call"
        _select.show()
        if _select.getindex() == 0:
            self.LastWindows.UiShow()
        else:
            cls()
            if self.mode == "dy":
                self.mode = _select.getvalue()
                self.UiShow()
            else:
                print(f"你决定前往: {self.mode} -> {_select.getvalue()}")
                old = self.saveattribute.getPlaydataJson()
                p = player_data(**old)
                p.Where = _select.getvalue()

                self.saveattribute.setPlaydataJson(p)

                self.LastWindows.UiShow()
    def Logic(self):
        ...

    def getAllDy(self) -> list:
        return self.mapSaveManager.all_dy

    def getAllPoint(self) -> list:
        return self.mapSaveManager.all_point
